package flc.ast.adapter;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.Random;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.bean.StkResBean;

public class NoteRankAdapter extends StkProviderMultiAdapter<StkResBean> {

    public NoteRankAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new NoteRankProvider());
    }

    private class NoteRankProvider extends BaseItemProvider<StkResBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_note_rank;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, StkResBean bean) {
            baseViewHolder.setText(R.id.tvNoteRankItemName, bean.getName());
            Random random = new Random();
            int num1 = random.nextInt(20);
            int num2 = random.nextInt(8) + 1;
            baseViewHolder.setText(R.id.tvNoteRankItemPopularity, getContext().getString(R.string.popularity_text, num1, num2));
            if (baseViewHolder.getBindingAdapterPosition() == 0) {
                baseViewHolder.setImageResource(R.id.ivNoteRankItemLog, R.drawable.atop1);
            } else if (baseViewHolder.getBindingAdapterPosition() == 1) {
                baseViewHolder.setImageResource(R.id.ivNoteRankItemLog, R.drawable.atop2);
            } else if (baseViewHolder.getBindingAdapterPosition() == 3) {
                baseViewHolder.setImageResource(R.id.ivNoteRankItemLog, R.drawable.atop3);
            }
        }
    }

}
